package com.woniuxy.controller;


import com.woniuxy.ResponseEntity.ResponseEntity;
import com.woniuxy.entity.Rbacmanager;
import com.woniuxy.service.ShiroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/rbac")
@RestController
public class RbacManagerController {

    @Autowired
    ShiroService ShiroService;

//    查询所有
    @PostMapping("/findAll/{currentPage}/{pageSize}")
    public ResponseEntity findAll(@PathVariable("currentPage")int currentPage,@PathVariable("pageSize") int pageSize,@RequestBody Rbacmanager Rbacmanager) {
        //调用Service实现类的方法
        System.out.println(currentPage+pageSize);
        ResponseEntity response = ShiroService.findAll(currentPage,pageSize,Rbacmanager);

        return response;
    }

//   根据id删除
   @DeleteMapping("/delete/{id}")
    public ResponseEntity delete(@PathVariable int id){
       //创建封装返回的对象
       ResponseEntity response = new ResponseEntity();

      if (ShiroService.deleteById(id)){
          response.setCode(200);
          response.setMessage("删除成功");
      }else {
          response.setCode(500);
          response.setMessage("删除失败");
      }

      return response;
    }

    //添加用户
    @RequestMapping("/add")
    public ResponseEntity add(@RequestBody Rbacmanager rbace){
        //创建封装返回的对象
        ResponseEntity response = new ResponseEntity();
       if (ShiroService.addRbac(rbace)){
           response.setCode(200);
           response.setMessage("添加成功");
       }else {
           response.setCode(500);
           response.setMessage("添加失败");
       }

        return response;
    }

    //修改用户
    @RequestMapping("/update")
    public ResponseEntity update(@RequestBody Rbacmanager rbace) {
        ResponseEntity response = new ResponseEntity();
        if (ShiroService.update(rbace)) {
            response.setCode(200);
            response.setMessage("修改成功");
        }else {
            response.setCode(500);
            response.setMessage("修改失败");
        }
        return response;
    }


}
